<template>
  <div class="result-box">
    <div class="result-title">{{ title }}</div>
    <div class="result-list">
      <template v-if="tagList.length == 0">
        <el-empty description="暂无结果" />
      </template>
      <template v-else>
        <el-tag
          v-for="tagInfo in tagList"
          :key="tagInfo[codeKey]"
          :type="type"
          closable
          class="tag-item"
          @close="handleRemoveTag(tagInfo)"
        >
          {{tagInfo[labelKey]}}
        </el-tag>
      </template>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    title: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: 'primary'
    },
    tagList: {
      type: Array,
      default: () => []
    },
    codeKey: {
      type: String,
      default: 'uuid'
    },
    labelKey: {
      type: String,
      default: 'name'
    }
  },
  methods: {
    handleRemoveTag (tagInfo) {
      this.$emit('remove', tagInfo)
    }
  }
}
</script>
<style lang="less" scoped>
.result-box {
  border: 1px solid #ccc;
  border-radius: 10px;
}
.result-title {
  padding: 10px 0 10px 10px;
  border-bottom: 1px solid #ccc;
}
.result-list {
  padding: 10px;
  height: 350px;
  overflow: hidden;
  overflow-y: auto;
}
.tag-item {
  width: 100%;
  position: relative;
  margin-bottom: 10px;
  &:last-child {
    margin-bottom: 0;
  }
  /deep/ .el-icon-close {
    position: absolute;
    top: 3px;
    right: 5px;
  }
}
</style>
